﻿using System;
using System.Collections.Generic;
using System.Web;
using System.IO;

namespace Hxj.Common
{
    /// <summary>
    ///Log4net 的摘要说明
    /// </summary>
    public class Log4net
    {
        //FATAL > ERROR > WARN > INFO > DEBUG

        static log4net.ILog log = log4net.LogManager.GetLogger("hxjlog");
        static Log4net()
        {
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(System.Web.HttpContext.Current.Server.MapPath(@"~/config/log4net.config")));
        }

        /// <summary>
        /// ilog
        /// </summary>
        /// <param name="logName"></param>
        /// <returns></returns>
        public static log4net.ILog GetLog(string logName)
        {
            return log;
        }

        /// <summary>
        /// debug
        /// </summary>
        /// <param name="message"></param>
        public static void debug(string message)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug(message);
            }
        }

        /// <summary>
        /// debug
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public static void debug(string message, Exception ex)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug(message, ex);
            }
        }

        /// <summary>
        /// error
        /// </summary>
        /// <param name="message"></param>
        public static void error(string message)
        {
            if (log.IsErrorEnabled)
            {
                log.Error(message);
            }
        }

        /// <summary>
        /// error
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public static void error(string message, Exception ex)
        {
            if (log.IsErrorEnabled)
            {
                log.Error(message, ex);
            }
        }

        /// <summary>
        /// fatal
        /// </summary>
        /// <param name="message"></param>
        public static void fatal(string message)
        {
            if (log.IsFatalEnabled)
            {
                log.Fatal(message);
            }
        }

        /// <summary>
        /// info
        /// </summary>
        /// <param name="message"></param>
        public static void info(string message)
        {
            if (log.IsInfoEnabled)
            {
                log.Info(message);
            }
        }

        /// <summary>
        /// warn
        /// </summary>
        /// <param name="message"></param>
        public static void warn(string message)
        {
            if (log.IsWarnEnabled)
            {
                log.Warn(message);
            }
        }
    }

}
